﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;
using FilStartUps.DAL;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_Forum : System.Web.UI.UserControl
    {
        private void GetForum()
        {

            //try
            //{
           
                var forum = FilStartUpsAPI.GetForumTopic();
            
                //var forum_ = (from u in db_connect.ForumThreads
                //                                    select u).ToList();
                dgForum.DataSource = forum;
                dgForum.DataBind();

                if (forum.Count < dgForum.PageSize)
                {
                    dgForum.PagerStyle.Visible = false;
                }
            
            //}
            //catch (Exception)
            //{

            //}
        }
        //Forum.aspx;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetForum();
            }
        }

        //Return 
        //Response.Redirect("ForumDisplay");
        //Report.aspx;
        //ForumReply.aspx;
        //NewThread.aspx;
        protected void dgForum_ItemCommand(object sender, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "SelectRow")
            {
                LinkButton hlforumtitle = (LinkButton)dgForum.Items[e.Item.ItemIndex].FindControl("hlForum");
                Label lbforumid = (Label)dgForum.Items[e.Item.ItemIndex].FindControl("lbforumid");

                bool views = FilStartUpsAPI.ForumViews(Convert.ToInt32(lbforumid.Text));

                Response.Redirect("~/ForumDisplay.aspx?f=" + lbforumid.Text);

            }
        }


    }
}